package com.hzspace.threadlocal;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2019/6/14_17:24
 */
public class Test {

    private static ThreadLocal<Local> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) {
        Local local = new Local();

        new Thread(() -> {
            for(int i=0;i<200;i++){
                threadLocal.set(local);
                Local l = threadLocal.get();
                l.setNumber(20);
                System.out.println(Thread.currentThread().getName() + "----" +threadLocal.get().getNumber());
                Thread.yield();
            }
        }).start();

        new Thread(() -> {
            for(int i=0;i<200;i++){
                threadLocal.set(local);
                Local l = threadLocal.get();
                l.setNumber(30);
                System.out.println(Thread.currentThread().getName() + "----" +threadLocal.get().getNumber());
                Thread.yield();
            }
        }).start();
    }
}
